import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import 'package:drm/base/base_list_page.dart';
import 'package:drm/util/SpUtils.dart';
import 'package:drm/base/user.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'wxd_bean.dart';
import 'package:drm/http/http_url.dart';
import 'wxd_bloc.dart';

class WxdPage extends StatefulWidget {
  int index;
  String title;

  WxdPage(this.index, {Key key, this.title}) : super(key: key);

  @override
  _WxdPageState createState() => _WxdPageState();
}
//with AutomaticKeepAliveClientMixin
class _WxdPageState extends BaseListPageState<WxdBloc, WxdBean, WxdPage>  {
  String ztInfo = '已维修';


  int selectedIndex = 0;

//  @override
//  bool get wantKeepAlive => true;
  @override
  iniBloc() {
    return WxdBloc();
  }

  @override
  iniRefushEvent() {
    Map<String, String> params = Map();
    params.putIfAbsent('Type', () => 'WXD');
    params.putIfAbsent('Rows', () => '${AppUrl.rows}');
    params.putIfAbsent('Page', () => '$page');
    params.putIfAbsent('FWSId', () => user.fwsId);
    params.putIfAbsent('ZTInfo', () => ztInfo);
    return WxdLoadDateEvent(params, portUrl: AppUrl.getGdfk());
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return super.build(context);
  }

  @override
  Widget iniHeaderView(BuildContext context) {
    return Container(
      color: Colors.white,
      height: 50,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          MaterialButton(
            color: selectedIndex == 0 ? ThemeData
                .light()
                .primaryColor : null,
            onPressed: () {
              selectedIndex = 0;
              ztInfo = '已派工';
              refresh();
            },
            child: Text('已派工', style: TextStyle(
                color: selectedIndex == 0 ? Colors.white : Colors.black87),),
          ),
          MaterialButton(
            color: selectedIndex == 1 ? ThemeData
                .light()
                .primaryColor : null,
            onPressed: () {
              selectedIndex = 1;
              ztInfo = '已维修';
              refresh();
            },
            child: Text('已维修', style: TextStyle(
                color: selectedIndex == 1 ? Colors.white : Colors.black87),),
          ),
        ],
      ),
    );
  }

  @override
  List<Widget> iniListItems(List<WxdBean> datas) {
    return datas.map((item) {
      return itemView(item);
    }).toList();
  }

  @override
  Widget inifootView(BuildContext context) {}


  Widget itemView(WxdBean item) {
    return Card(
      elevation: 0,
        child: Padding(
          padding: EdgeInsets.only(left: 16, right: 16, bottom: 10),
          child: ListTile(
            title: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
//                Padding(padding: EdgeInsets.only(top: 5, bottom: 5),
//                  child: Text('${item.kH}  ( ${item.xDSD} )', style: TextStyle(
//                    fontSize: 17,),),),
//                Padding(padding: EdgeInsets.only(top: 3,),
//                  child: Text('电话：${item.lXDH}', style: TextStyle(
//                    fontSize: 15,),),),
//                Padding(padding: EdgeInsets.only(top: 3,),
//                  child: Text('地址：${item.sHDZ}', style: TextStyle(
//                    fontSize: 15,),),),
//                Padding(padding: EdgeInsets.only(top: 3,bottom: 3),
//                  child: Text('安装：${item.yYAZ}', style: TextStyle(
//                    fontSize: 15,),),),
              
              ],
            ),
            subtitle: item.bZ.isEmpty? null : Text('${item.bZ}',maxLines: 2,overflow: TextOverflow.ellipsis,),
            onTap: () {

            },
          ))

    );
  }
}
